package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.RPage;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WGood;
import com.ruoyi.system.domain.WGoodsRecords;
import com.ruoyi.system.domain.vo.WGoodVO;
import com.ruoyi.system.domain.vo.WGoodsRecordsVO;
import com.ruoyi.system.domain.vo.WOrderVO;
import com.ruoyi.system.service.IWGoodService;
import com.ruoyi.system.service.IWGoodsRecordsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物品Controller
 * 
 * @author ruoyi
 * @date 2021-12-05
 */

@Api("物料控制器")
@RestController
@RequestMapping("/system/good")
public class WGoodController extends BaseController
{
    @Autowired
    private IWGoodService wGoodService;
    @Autowired
    private IWGoodsRecordsService wGoodsRecordsService;
    
    @ApiOperation("物料详情数据")
    @GetMapping(value = "getGood/{id}")
    public R<WGoodVO> getGood(@PathVariable("id") Long id)
    {
        WGoodVO selectWGoodByIdNew = wGoodService.selectWGoodByIdNew(id);
		return R.success(selectWGoodByIdNew);
    }

    /**
     * 修改物品
     */
    @ApiOperation("盘点物品接口 -- 直接整体覆盖物品数量 --单独盘点的 不是针对发料的盘点")
    @PostMapping("check")
    public R check(@RequestBody List<WGoodsRecords> wGoodsRecordsList)
    {
    	LoginUser loginUser = getLoginUser();
    	wGoodsRecordsList.forEach(e->{
    		e.setCreateBy(loginUser.getUsername());
    		e.setCreateTime(new Date());
    	});
    	
        return wGoodsRecordsService.check(wGoodsRecordsList);
    }
    
    
    
    
    @ApiOperation("客户查询盘点记录列表  ， 传goodId 就是查询某一个物品的盘点")
    @GetMapping("checkList")
    public RPage<WGoodsRecords> checkList(WGoodsRecords wGoodsRecords)
    {
    	wGoodsRecords.setIsIn(2);
        startPage();
        List<WGoodsRecords> list = wGoodsRecordsService.selectWGoodsRecordsList(wGoodsRecords);
        return getRPageTable(list);
    }
    
    @ApiOperation("客户查询物料使用记录列表  ， 传goodId 就是查询某一个物品的盘点,  ")
    @GetMapping("goodRecoordsUseList")
    public RPage<WGoodsRecordsVO> goodRecoordsList(WGoodsRecordsVO wGoodsRecords)
    {
    	wGoodsRecords.setIsIn(1);
        startPage();
        List<WGoodsRecordsVO> list = wGoodsRecordsService.selectWGoodsRecordsListNew(wGoodsRecords);
        return getRPageTable(list);
    }


    
    /**
     * 查询物品列表
     */
    @ApiOperation("客户查询仓库物料列表")
    @GetMapping("/customerList")
    public RPage<WGoodVO> customerList(WGoodVO wGood)
    {
    	wGood.setCustomerId(getUserId());
        startPage();
        List<WGoodVO> list = wGoodService.selectWGoodList(wGood);
        return getRPageTable(list);
    }
    @ApiOperation("仓库查询仓库物料列表")
    @GetMapping("/fList")
    public RPage<WGoodVO> fList(WGoodVO wGood)
    {
    	wGood.setDeptId(getDeptId()); 
    	startPage();
    	List<WGoodVO> list = wGoodService.selectWGoodList(wGood);
    	return getRPageTable(list);
    }
    
    @ApiOperation("删除物料")
    @GetMapping("delete/{id}")
    public R remove(@PathVariable("id") Long id)
    {
        return  wGoodService.delete(id);
    }


    /**
     * 导出物品列表
     */
//    @PreAuthorize("@ss.hasPermi('system:good:export')")
//    @Log(title = "物品", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(WGood wGood)
//    {
//        List<WGood> list = wGoodService.selectWGoodList(wGood);
//        ExcelUtil<WGood> util = new ExcelUtil<WGood>(WGood.class);
//        return util.exportExcel(list, "物品数据");
//    }
//
//   
    


     
}
